<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/13
 * Time: 15:57
 */
session_start();
include 'conn.php';



   
    $role=$_POST['role'];
    $user=$_POST['userName'];
    $pwd=$_POST['passWorld'];

    if($user==null||$user==""){
        ?>
        <meta charset="UTF-8">
        <script type="text/javascript">
            alert("用户名不能为空");
        </script>
        <?
        echo "<script language=\"javascript\">location.href='login.html';</script>";
    }
    if($pwd==null||$pwd==""){
        ?>
        <meta charset="UTF-8">
        <script type="text/javascript">
            alert("密码不能为空");
        </script>
        <?
        echo "<script language=\"javascript\">location.href='login.html';</script>";
    }

    switch($role) {
        case 0:
            $sql="select * from administrator WHERE AdministratorId=$user AND Password=$pwd";
            $result=mysqli_query($conn,$sql);

            if ($result->num_rows>0) {
                header("Location:h-admin/a-index.php");
                 setcookie("cookie","a-ok",time()+3600,"/");
                     $_SESSION["a-id"]=$_POST["userName"];
   					 $_SESSION["a-Year"]=$_POST['year'];
            }
            else
            {
                ?>
                <meta charset="UTF-8">
                <script type="text/javascript">
                    alert("密码或用户名不正确");
                </script>
                <?
                echo "<script language=\"javascript\">location.href='login.html';</script>";
            }break;
        case 1:
            $sql="select * from teacher WHERE TeacherId=$user AND TeacherPassword=$pwd";
            $result=mysqli_query($conn,$sql);
            if ($result->num_rows>0) {
                header("Location:h-teacher/t-index.php");
                setcookie("cookie","t-ok",time()+3600,"/");
                     $_SESSION["t-id"]=$_POST["userName"];
   					 $_SESSION["t-Year"]=$_POST['year'];
            } else
            {
                ?>
                <meta charset="UTF-8">
                <script type="text/javascript">
                    alert("密码或用户名不正确");
                </script>
                <?
                echo "<script language=\"javascript\">location.href='login.html';</script>";
            }break;
        case 2:
            $sql="select * from student WHERE StudentId=$user AND StudtentPassword=$pwd";
            $result=mysqli_query($conn,$sql);
            if($result->num_rows>0){

                header("Location:h-student/s-index.php");
                setcookie("cookie","s-ok",time()+3600,"/");
                     $_SESSION["s-id"]=$_POST["userName"];
   					 $_SESSION["s-Year"]=$_POST['year'];
            }
            else
            {
                ?>
                <meta charset="UTF-8">
                <script type="text/javascript">
                    alert("密码或用户名不正确");
                </script>
                <?
                echo "<script language=\"javascript\">location.href='login.html';</script>";
            }break;

    }


?>

